package com.neusoft.dao.impl;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.neusoft.dao.UmsAdminDao;
import com.neusoft.model.UmsAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

/**
 * @Author: duan
 * @Date: Create in 20:35 2020/10/27
 */
//<bean id="umsAdminDao" class="com.neusoft.dao.impl.UmsAdminDaoImpl"></bean>
@Repository("umsAdminDao")
public class UmsAdminDaoImpl implements UmsAdminDao {
    @Autowired
    private DruidDataSource dataSource;

    @Override
    public UmsAdmin queryById(Long id) {
        DruidPooledConnection connection = null;
        try {
            connection = dataSource.getConnection();
            String sql = "select * from ums_admin where id = ?";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setLong(1, id);
            ResultSet rs = preparedStatement.executeQuery();
            System.out.println(preparedStatement.toString());
            if (rs.next()) {
                System.out.println(rs);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        return null;
    }

    @Override
    public List<UmsAdmin> queryAllByLimit(int offset, int limit) {
        return null;
    }

    @Override
    public List<UmsAdmin> queryAll(UmsAdmin umsAdmin) {
        return null;
    }

    @Override
    public int insert(UmsAdmin umsAdmin) {
        return 0;
    }

    @Override
    public int update(UmsAdmin umsAdmin) {
        return 0;
    }

    @Override
    public int deleteById(Long id) {
        return 0;
    }
}
